home *** CD-ROM | disk | FTP | other *** search
/ Chip 2006 July / CHIP 2006-07.2.iso / program / web_gelistirme / easyphp1-7_setup.exe / {app} / phpmyadmin / server_databases.php < prev    next >
Encoding:
PHP Script  |  2003-09-07  |  17.0 KB  |  366 lines

  1. <?php
  2. /* $Id: server_databases.php,v 1.12 2003/05/30 21:11:47 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Checks if the left frame has to be reloaded
  8.  */
  9. require('./libraries/grab_globals.lib.php');
  10.  
  11.  
  12. /**
  13.  * Does the common work
  14.  */
  15. $js_to_run = 'functions.js';
  16. require('./server_common.inc.php');
  17.  
  18.  
  19. /**
  20.  * Sorts the databases array according to the user's choice
  21.  *
  22.  * @param   array    a record associated to a database
  23.  * @param   array    a record associated to a database
  24.  *
  25.  * @return  integer  a value representing whether $a should be before $b in the
  26.  *                   sorted array or not
  27.  *
  28.  * @global  string   the column the array shall be sorted by
  29.  * @global  string   the sorting order ('asc' or 'desc')
  30.  *
  31.  * @access  private
  32.  */
  33. function PMA_dbCmp($a, $b)
  34. {
  35.     global $sort_by, $sort_order;
  36.     if ($sort_by == 'db_name') {
  37.         return ($sort_order == 'asc' ? 1 : -1) * strcasecmp($a['db_name'], $b['db_name']);
  38.     } else if ($a[$sort_by] == $b[$sort_by]) {
  39.         return strcasecmp($a['db_name'], $b['db_name']);
  40.     } else {
  41.         return ($sort_order == 'asc' ? 1 : -1) * ((int)$a[$sort_by] > (int)$b[$sort_by] ? 1 : -1);
  42.     }
  43. } // end of the 'PMA_dbCmp()' function
  44.  
  45.  
  46. /**
  47.  * Gets the databases list - if it has not been built yet
  48.  */
  49. if ($server > 0 && empty($dblist)) {
  50.     PMA_availableDatabases();
  51. }
  52.  
  53.  
  54. /**
  55.  * Drops multiple databases
  56.  */
  57. if ((!empty($drop_selected_dbs) || isset($query_type)) && ($is_superuser || $cfg['AllowUserDropDatabase'])) {
  58.     if (empty($selected_db) && ! (isset($query_type) && !empty($selected))) {
  59.         $message = $strNoDatabasesSelected;
  60.     } else {
  61.         $action = 'server_databases.php';
  62.         $submit_mult = 'drop_db' ;
  63.         $err_url = 'server_databases.php?' . PMA_generate_common_url();
  64.         include('./mult_submits.inc.php');
  65.         $message = sprintf($strDatabasesDropped, count($selected));
  66.         // we need to reload the database list now.
  67.         PMA_availableDatabases();
  68.         $reload = 1;
  69.     }
  70. }
  71.  
  72.  
  73. /**
  74.  * Displays the links
  75.  */
  76. require('./server_links.inc.php');
  77.  
  78.  
  79. /**
  80.  * Displays the sub-page heading
  81.  */
  82. echo '<h2>' . "\n"
  83.    . '    ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n"
  84.    . '</h2>' . "\n";
  85.  
  86.  
  87. /**
  88.  * Checks if the user is allowed to do what he tries to...
  89.  */
  90. if (!empty($dbstats) && (!$is_superuser || PMA_MYSQL_INT_VERSION < 32303)) {
  91.     echo $strNoPrivileges . "\n";
  92.     include('./footer.inc.php');
  93.     exit;
  94. }
  95.  
  96.  
  97. /**
  98.  * Prepares the statistics
  99.  */
  100. $statistics = array();
  101. while (list(, $current_db) = each($dblist)) {
  102.     $tmp_array = array(
  103.         'db_name' => $current_db,
  104.         'tbl_cnt' => 0,
  105.         'data_sz' => 0,
  106.         'idx_sz' => 0,
  107.         'tot_sz' => 0
  108.     );
  109.     if (!empty($dbstats)) {
  110.         $res = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';');
  111.         while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) {
  112.             $tmp_array['tbl_cnt']++;
  113.             $tmp_array['data_sz'] += $row['Data_length'];
  114.             $tmp_array['idx_sz'] += $row['Index_length'];
  115.         }
  116.     }
  117.     $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz'];
  118.     $statistics[] = $tmp_array;
  119. }
  120.  
  121. // avoids 'undefined index' errors
  122. if (empty($sort_by)) {
  123.     $sort_by = 'db_name';
  124. }
  125. if (empty($sort_order)) {
  126.     if ($sort_by == 'db_name') {
  127.         $sort_order = 'asc';
  128.     } else {
  129.         $sort_order = 'desc';
  130.     }
  131. }
  132.  
  133. // sorts the array
  134. usort($statistics, 'PMA_dbCmp');
  135.  
  136.  
  137. /**
  138.  * Displays the page
  139.  */
  140. if (count($statistics) > 0) {
  141.     echo '<form action="./server_databases.php" method="post" name="dbStatsForm">' . "\n"
  142.        . PMA_generate_common_hidden_inputs('', '', 1)
  143.        . '    <input type="hidden" name="dbstats" value="' . (empty($dbstats) ? '0' : '1') . '" />' . "\n"
  144.        . '    <input type="hidden" name="sort_by" value="' . $sort_by . '" />' . "\n"
  145.        . '    <input type="hidden" name="sort_order" value="' . $sort_order . '" />' . "\n"
  146.        . '    <table border="0">' . "\n"
  147.        . '        <tr>' . "\n"
  148.        . ($is_superuser || $cfg['AllowUserDropDatabase'] ? '            <th> </th>' . "\n" : '')
  149.        . '            <th>' . "\n"
  150.        . '                 ';
  151.     if (empty($dbstats)) {
  152.         echo $strDatabase . "\n"
  153.            . '                <img src="./images/asc_order.png" border="0" width="7" height="7"  alt="' . $strAscending . '" />' . "\n"
  154.            . '                 ' . "\n"
  155.            . '            </th>' . "\n";
  156.     } else {
  157.         echo "\n"
  158.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=db_name&sort_order=' . (($sort_by == 'db_name' && $sort_order == 'asc') ? 'desc' : 'asc') . '">' . "\n"
  159.            . '                    ' . $strDatabase . "\n"
  160.            . ($sort_by == 'db_name' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  161.            . '                </a>' . "\n"
  162.            . '                 ' . "\n"
  163.            . '            </th>' . "\n"
  164.            . '            <th>' . "\n"
  165.            . '                 ' . "\n"
  166.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=tbl_cnt&sort_order=' . (($sort_by == 'tbl_cnt' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  167.            . '                    ' . $strNumTables . "\n"
  168.            . ($sort_by == 'tbl_cnt' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  169.            . '                </a>' . "\n"
  170.            . '                 ' . "\n"
  171.            . '            </th>' . "\n"
  172.            . '            <th colspan="2">' . "\n"
  173.            . '                 ' . "\n"
  174.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=data_sz&sort_order=' . (($sort_by == 'data_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  175.            . '                    ' . $strData . "\n"
  176.            . ($sort_by == 'data_sz' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  177.            . '                </a>' . "\n"
  178.            . '                 ' . "\n"
  179.            . '            </th>' . "\n"
  180.            . '            <th colspan="2">' . "\n"
  181.            . '                 ' . "\n"
  182.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=idx_sz&sort_order=' . (($sort_by == 'idx_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  183.            . '                    ' . $strIndexes . "\n"
  184.            . ($sort_by == 'idx_sz' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  185.            . '                </a>' . "\n"
  186.            . '                 ' . "\n"
  187.            . '            </th>' . "\n"
  188.            . '            <th colspan="2">' . "\n"
  189.            . '                 ' . "\n"
  190.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1&sort_by=tot_sz&sort_order=' . (($sort_by == 'tot_sz' && $sort_order == 'desc') ? 'asc' : 'desc') . '">' . "\n"
  191.            . '                    ' . $strTotalUC . "\n"
  192.            . ($sort_by == 'tot_sz' ? '                    <img src="./images/' . $sort_order . '_order.png" border="0" width="7" height="7"  alt="' . ($sort_order == 'asc' ? $strAscending : $strDescending) . '" />' . "\n" : '')
  193.            . '                </a>' . "\n"
  194.            . '                 ' . "\n"
  195.            . '            </th>' . "\n";
  196.     }
  197.     if ($is_superuser) {
  198.         echo '            <th>' . "\n"
  199.            . '                 ' . $strAction . ' ' . "\n"
  200.            . '            </th>' . "\n";
  201.     }
  202.     echo '        </tr>' . "\n";
  203.     $useBgcolorOne = TRUE;
  204.     $total_calc = array(
  205.         'db_cnt' => 0,
  206.         'tbl_cnt' => 0,
  207.         'data_sz' => 0,
  208.         'idx_sz' => 0,
  209.         'tot_sz' => 0
  210.     );
  211.     while (list(, $current) = each($statistics)) {
  212.         list($data_size, $data_unit) = PMA_formatByteDown($current['data_sz'], 3, 1);
  213.         list($idx_size, $idx_unit)   = PMA_formatByteDown($current['idx_sz'], 3, 1);
  214.         list($tot_size, $tot_unit)   = PMA_formatByteDown($current['tot_sz'], 3, 1);
  215.         $total_calc['db_cnt']++;
  216.         $total_calc['tbl_cnt'] += $current['tbl_cnt'];
  217.         $total_calc['data_sz'] += $current['data_sz'];
  218.         $total_calc['idx_sz'] += $current['idx_sz'];
  219.         $total_calc['tot_sz'] += $current['tot_sz'];
  220.         echo '        <tr>' . "\n";
  221.         if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  222.             echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  223.                . '                <input type="checkbox" name="selected_db[]" title="' . htmlspecialchars($current['db_name']) . '" value="' . htmlspecialchars($current['db_name']) . '" ' . (empty($checkall) ? '' : 'checked="checked" ') . '/>' . "\n"
  224.                . '            </td>' . "\n";
  225.         }
  226.         echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  227.            . '                <a href="' . $cfg['DefaultTabDatabase'] . '?' . $url_query . '&db=' . urlencode($current['db_name']) . '" title="' . sprintf($strJumpToDB, htmlspecialchars($current['db_name'])) . '">' . "\n"
  228.            . '                    ' . htmlspecialchars($current['db_name']) . "\n"
  229.            . '                </a>' . "\n"
  230.            . '            </td>' . "\n";
  231.         if (!empty($dbstats)) {
  232.             echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  233.                . '                ' . $current['tbl_cnt'] . "\n"
  234.                . '            </td>' . "\n"
  235.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  236.                . '                ' . $data_size . "\n"
  237.                . '            </td>' . "\n"
  238.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  239.                . '                ' . $data_unit . "\n"
  240.                . '            </td>' . "\n"
  241.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  242.                . '                ' . $idx_size . "\n"
  243.                . '            </td>' . "\n"
  244.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  245.                . '                ' . $idx_unit . "\n"
  246.                . '            </td>' . "\n"
  247.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '" align="right">' . "\n"
  248.                . '                <b>' . "\n"
  249.                . '                    ' . $tot_size . "\n"
  250.                . '                </b>' . "\n"
  251.                . '            </td>' . "\n"
  252.                . '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  253.                . '                <b>' . "\n"
  254.                . '                    ' . $tot_unit . "\n"
  255.                . '                </b>' . "\n"
  256.                . '            </td>' . "\n";
  257.         }
  258.         if ($is_superuser) {
  259.             echo '            <td bgcolor="' . ($useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']) . '">' . "\n"
  260.                . '                <a href="./server_privileges.php?' . $url_query . '&checkprivs=' . urlencode($current['db_name']) . '" title="' . sprintf($strCheckPrivsLong, htmlspecialchars($current['db_name'])) . '">'. "\n"
  261.                . '                    ' . $strCheckPrivs . "\n"
  262.                . '                </a>' . "\n"
  263.                . '            </td>' . "\n";
  264.         }
  265.         echo '        </tr>' . "\n";
  266.         $useBgcolorOne = !$useBgcolorOne;
  267.     } // end while
  268.     if (!empty($dbstats)) {
  269.         list($data_size, $data_unit) = PMA_formatByteDown($total_calc['data_sz'], 3, 1);
  270.         list($idx_size, $idx_unit)   = PMA_formatByteDown($total_calc['idx_sz'], 3, 1);
  271.         list($tot_size, $tot_unit)   = PMA_formatByteDown($total_calc['tot_sz'], 3, 1);
  272.         echo '        <tr>' . "\n"
  273.            . '            <th> </th>' . "\n"
  274.            . '            <th>' . "\n"
  275.            . '                 ' . $strTotalUC . ': ' . $total_calc['db_cnt'] . ' ' . "\n"
  276.            . '            </th>' . "\n"
  277.            . '            <th align="right">' . "\n"
  278.            . '                 ' . $total_calc['tbl_cnt'] . ' ' . "\n"
  279.            . '            </th>' . "\n"
  280.            . '            <th align="right">' . "\n"
  281.            . '                 ' . $data_size . "\n"
  282.            . '            </th>' . "\n"
  283.            . '            <th align="left">' . "\n"
  284.            . '                ' . $data_unit . ' ' . "\n"
  285.            . '            </th>' . "\n"
  286.            . '            <th align="right">' . "\n"
  287.            . '                 ' . $idx_size . "\n"
  288.            . '            </th>' . "\n"
  289.            . '            <th align="left">' . "\n"
  290.            . '                ' . $idx_unit . ' ' . "\n"
  291.            . '            </th>' . "\n"
  292.            . '            <th align="right">' . "\n"
  293.            . '                 ' . $tot_size . "\n"
  294.            . '            </th>' . "\n"
  295.            . '            <th align="left">' . "\n"
  296.            . '                ' . $tot_unit . ' ' . "\n"
  297.            . '            </th>' . "\n"
  298.            . '            <th> </th>' . "\n"
  299.            . '        </tr>' . "\n";
  300.     }
  301.     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  302.         $common_url_query = PMA_generate_common_url() . '&sort_by=' . $sort_by . '&sort_order=' . $sort_order . '&dbstats=' . (empty($dbstats) ? '10' : '3');
  303.         echo '    <tr>' . "\n"
  304.            . '        <td colspan="' . (empty($dbstats) ? '10' : '3') . '">' . "\n"
  305.            . '            <img src="./images/arrow_' . $text_dir . '.gif" border="0" width="38" height="22" alt="' . $strWithChecked . '" />' . "\n"
  306.            . '            <a href="./server_databases.php?' . $common_url_query . '&checkall=1" onclick="setCheckboxes(\'dbStatsForm\', true); return false;">' . "\n"
  307.            . '                ' . $strCheckAll
  308.            . '            </a>' . "\n"
  309.            . '             / ' . "\n"
  310.            . '            <a href="./server_databases.php?' . $common_url_query . '" onclick="setCheckboxes(\'dbStatsForm\', false); return false;">' . "\n"
  311.            . '                ' . $strUncheckAll
  312.            . '            </a>' . "\n"
  313.            . '        </td>' . "\n"
  314.            . '    </tr>' . "\n";
  315.     }
  316.     echo '    </table>' . "\n";
  317.     unset($data_size);
  318.     unset($data_unit);
  319.     unset($idx_size);
  320.     unset($idx_unit);
  321.     unset($tot_size);
  322.     unset($tot_unit);
  323.     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  324.         echo '    <ul>' . "\n";
  325.     }
  326.     if ($is_superuser && empty($dbstats) && PMA_MYSQL_INT_VERSION >= 32303) {
  327.         echo '        <li>' . "\n"
  328.            . '            <b>' . "\n"
  329.            . '                <a href="./server_databases.php?' . $url_query . '&dbstats=1" title="' . $strDatabasesStatsEnable . '">' . "\n"
  330.            . '                    ' . $strDatabasesStatsEnable . "\n"
  331.            . '                </a>' . "\n"
  332.            . '            </b>' . "\n"
  333.            . '            <br />' . "\n"
  334.            . '            ' . $strDatabasesStatsHeavyTraffic . "\n"
  335.            . '        </li><br /><br />' . "\n";
  336.     } else if ($is_superuser && !empty($dbstats)) {
  337.         echo '        <li>' . "\n"
  338.            . '            <b>' . "\n"
  339.            . '                <a href="./server_databases.php?' . $url_query . '" title="' . $strDatabasesStatsDisable . '">'. "\n"
  340.            . '                    ' . $strDatabasesStatsDisable . "\n"
  341.            . '                </a>' . "\n"
  342.            . '            </b>' . "\n"
  343.            . '        </li><br /><br />' . "\n";
  344.     }
  345.     if ($is_superuser || $cfg['AllowUserDropDatabase']) {
  346.         echo '        <li>' . "\n"
  347.            . '            <b>' . "\n"
  348.            . '                ' . $strDropSelectedDatabases . "\n"
  349.            . '            </b><br />' . "\n"
  350.            . '            <input type="submit" name="drop_selected_dbs" value="' . $strGo . '" />' . "\n"
  351.            . '        </li>' . "\n"
  352.            . '    </ul>' . "\n";
  353.     }
  354.     echo '</form>' . "\n";
  355. } else {
  356.     echo $strNoDatabases . "\n";
  357. }
  358.  
  359.  
  360. /**
  361.  * Sends the footer
  362.  */
  363. require('./footer.inc.php');
  364.  
  365. ?>
  366.